namespace IniTechCaash.Domain.Migrations
{
    using System;
    using System.Data.Entity;
    using System.Data.Entity.Migrations;
    using System.Linq;
    using IniTechCaash.Domain.Entities;
    using IniTechCaash.Utility;

    internal sealed class Configuration : DbMigrationsConfiguration<IniTechCaash.Domain.EntityFramework.CaashContext>
    {
        public Configuration()
        {
            AutomaticMigrationsEnabled = false;
        }

        protected override void Seed(IniTechCaash.Domain.EntityFramework.CaashContext context)
        {
            //  This method will be called after migrating to the latest version.

            //  You can use the DbSet<T>.AddOrUpdate() helper extension method 
            //  to avoid creating duplicate seed data. E.g.
            //
            //    context.People.AddOrUpdate(
            //      p => p.FullName,
            //      new Person { FullName = "Andrew Peters" },
            //      new Person { FullName = "Brice Lambson" },
            //      new Person { FullName = "Rowan Miller" }
            //    );
            //

            DateTime timeStamp = DateTime.Now;

            context.Accounts.AddOrUpdate
            (
                a => a.Name,
                new Account
                {
                    CreatedBy = "wmasters",
                    CreatedDate = DateTime.Now,
                    Description = "Primary cash account.",
                    IsEnabled = true,
                    LastModifiedBy = "wmasters",
                    LastModifiedDate = DateTime.Now,
                    Name = "Cash",
                    Number = "100000000",
                    Type = AccountType.CurrentAsset,
                },
                new Account
                {
                    CreatedBy = "wmasters",
                    CreatedDate = DateTime.Now,
                    Description = "Cost of goods sold.",
                    IsEnabled = true,
                    LastModifiedBy = "wmasters",
                    LastModifiedDate = DateTime.Now,
                    Name = "Cost of Goods Sold",
                    Number = "300000000",
                    Type = AccountType.CostOfGoodsSoldExpense,
                },
                new Account
                {
                    CreatedBy = "wmasters",
                    CreatedDate = DateTime.Now,
                    Description = "Rent for our primary headquarters in Chicago.",
                    IsEnabled = true,
                    LastModifiedBy = "wmasters",
                    LastModifiedDate = DateTime.Now,
                    Name = "Rent Expense",
                    Number = "300000001",
                    Type = AccountType.Expense,
                },
                new Account
                {
                    CreatedBy = "wmasters",
                    CreatedDate = DateTime.Now,
                    Description = "Utilities for our primary headquarters in Chicago.",
                    IsEnabled = true,
                    LastModifiedBy = "wmasters",
                    LastModifiedDate = DateTime.Now,
                    Name = "Utilities Expense",
                    Number = "300000002",
                    Type = AccountType.Expense,
                },
                new Account
                {
                    CreatedBy = "wmasters",
                    CreatedDate = DateTime.Now,
                    Description = "Primary service revenue account.",
                    IsEnabled = true,
                    LastModifiedBy = "wmasters",
                    LastModifiedDate = DateTime.Now,
                    Name = "Service Revenue",
                    Number = "500000000",
                    Type = AccountType.ServiceRevenue,
                },
                new Account
                {
                    CreatedBy = "wmasters",
                    CreatedDate = DateTime.Now,
                    Description = "Primary sales revenue account.",
                    IsEnabled = true,
                    LastModifiedBy = "wmasters",
                    LastModifiedDate = DateTime.Now,
                    Name = "Sales Revenue",
                    Number = "500000001",
                    Type = AccountType.SalesRevenue,
                },
                new Account
                {
                    CreatedBy = "wmasters",
                    CreatedDate = DateTime.Now,
                    Description = "Primary cash account.",
                    IsEnabled = true,
                    LastModifiedBy = "wmasters",
                    LastModifiedDate = DateTime.Now,
                    Name = "Merchandise Inventory",
                    Number = "100000001",
                    Type = AccountType.InventoryAsset,
                },
                new Account
                {
                    CreatedBy = "wmasters",
                    CreatedDate = DateTime.Now,
                    Description = "Equity imparted by the purchase of common stock.",
                    IsEnabled = true,
                    LastModifiedBy = "wmasters",
                    LastModifiedDate = DateTime.Now,
                    Name = "Common Stock Class A",
                    Number = "200000000",
                    Type = AccountType.CommonStockEquity,
                }
            );

            context.Users.AddOrUpdate
            (
                u => u.UserName,
                new User { CreatedBy = Constants.SystemUserName, CreatedDate = timeStamp, LastModifiedBy = Constants.SystemUserName, LastModifiedDate = timeStamp, UserName = "wmasters", UserPassword = "wmasters" },
                new User { CreatedBy = Constants.SystemUserName, CreatedDate = timeStamp, LastModifiedBy = Constants.SystemUserName, LastModifiedDate = timeStamp, UserName = "jpinott", UserPassword = "jpinott" }
            );

            context.SaveChanges();
        }
    }
}
